package com.amading.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.util.HashMap;
import java.util.Map;

@Controller
public class UploadController {
    @PostMapping("/upload_audio")
    @ResponseBody
    public Map<String,Object> uploadAudio(@RequestParam("file")MultipartFile uploadFile){
        Map<String,Object> map=new HashMap<>(16);

        if(uploadFile.isEmpty()){
            map.put("code",-1);
            map.put("data","");
            return map;
        }

        String fileName=System.currentTimeMillis()+".aac";

        File file=new File("D:\\static\\"+fileName);

        try {
            uploadFile.transferTo(file);

            map.put("code",0);
            map.put("data",fileName);
            return map;

        }catch (Exception e){
            e.printStackTrace();

            map.put("code",-1);
            map.put("data","");
            return map;
        }





    }
}
